import { apiService } from './api'
import { API_ENDPOINTS } from '@/config/api'

// 产品接口
export interface Product {
  id: string
  name: string
  public_id: string
  latest_version: string
  sign_type: string
  sign_key: string
  created_at: string
  updated_at: string
}

// 创建产品请求
export interface CreateProductRequest {
  name: string
  public_id: string
  latest_version?: string
  sign_type: string
  sign_key: string
}

// 更新产品请求
export interface UpdateProductRequest {
  name?: string
  public_id?: string
  latest_version?: string
  sign_type?: string
  sign_key?: string
}

// 产品服务
export const productService = {
  // 获取产品列表
  getProducts: (): Promise<Product[]> => {
    return apiService.get<Product[]>(API_ENDPOINTS.PRODUCTS)
  },

  // 获取单个产品
  getProduct: (id: string): Promise<Product> => {
    return apiService.get<Product>(API_ENDPOINTS.PRODUCT(id))
  },

  // 创建产品
  createProduct: (data: CreateProductRequest): Promise<Product> => {
    return apiService.post<Product>(API_ENDPOINTS.PRODUCTS, data)
  },

  // 更新产品
  updateProduct: (id: string, data: UpdateProductRequest): Promise<Product> => {
    return apiService.put<Product>(API_ENDPOINTS.PRODUCT(id), data)
  },

  // 删除产品
  deleteProduct: (id: string): Promise<{ message: string }> => {
    return apiService.delete<{ message: string }>(API_ENDPOINTS.PRODUCT(id))
  }
} 